package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyReportReason;
import com.ruoyi.system.service.ISysCompanyReportReasonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诊断报告原因模版库Controller
 * 
 * @author ruoyi
 * @date 2023-08-19
 */
@Api(tags = "企业诊断报告原因模版库")
@RestController
@RequestMapping("/system/reason")
public class SysCompanyReportReasonController extends BaseController
{
    @Autowired
    private ISysCompanyReportReasonService sysCompanyReportReasonService;

    /**
     * 查询诊断报告原因模版库列表
     */
    //  @PreAuthorize("@ss.hasPermi('system:reason:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询诊断报告原因模版库列表")
    public AjaxResult list(SysCompanyReportReason sysCompanyReportReason)
    {
        if(!getLoginUser().getUser().isAdmin()){
            sysCompanyReportReason.setUserId(getLoginUser().getUserId());
        }
        List<SysCompanyReportReason> list = sysCompanyReportReasonService.selectSysCompanyReportReasonList(sysCompanyReportReason);
        return AjaxResult.success(list);
    }

    /**
     * 查询诊断报告原因模版库列表
     */
  //  @PreAuthorize("@ss.hasPermi('system:reason:list')")
    @GetMapping("/page")
    @ApiOperation(value = "查询诊断报告原因模版库列表(分页)")
    public TableDataInfo listPage(SysCompanyReportReason sysCompanyReportReason)
    {
        startPage();
        if(!getLoginUser().getUser().isAdmin()){
            sysCompanyReportReason.setUserId(getLoginUser().getUserId());
        }
        List<SysCompanyReportReason> list = sysCompanyReportReasonService.selectSysCompanyReportReasonList(sysCompanyReportReason);
        return getDataTable(list);
    }

    /**
     * 导出诊断报告原因模版库列表
     */
  //  @PreAuthorize("@ss.hasPermi('system:reason:export')")
    @Log(title = "诊断报告原因模版库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyReportReason sysCompanyReportReason)
    {
        List<SysCompanyReportReason> list = sysCompanyReportReasonService.selectSysCompanyReportReasonList(sysCompanyReportReason);
        ExcelUtil<SysCompanyReportReason> util = new ExcelUtil<SysCompanyReportReason>(SysCompanyReportReason.class);
        util.exportExcel(response, list, "诊断报告原因模版库数据");
    }

    /**
     * 获取诊断报告原因模版库详细信息
     */
  //  @PreAuthorize("@ss.hasPermi('system:reason:query')")
    @GetMapping(value = "/{reasonId}")
    @ApiOperation(value = "获取诊断报告原因模版库详细信息")
    public AjaxResult getInfo(@PathVariable("reasonId") Long reasonId)
    {
        return AjaxResult.success(sysCompanyReportReasonService.selectSysCompanyReportReasonByReasonId(reasonId));
    }

    /**
     * 新增诊断报告原因模版库
     */
   // @PreAuthorize("@ss.hasPermi('system:reason:add')")
    @Log(title = "诊断报告原因模版库", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增诊断报告原因模版库")
    public AjaxResult add(@RequestBody SysCompanyReportReason sysCompanyReportReason)
    {
        sysCompanyReportReason.setCreateBy(getLoginUser().getUsername());
        sysCompanyReportReason.setUserId(getLoginUser().getUserId());
        return toAjax(sysCompanyReportReasonService.insertSysCompanyReportReason(sysCompanyReportReason));
    }

    /**
     * 修改诊断报告原因模版库
     */
  //  @PreAuthorize("@ss.hasPermi('system:reason:edit')")
    @Log(title = "诊断报告原因模版库", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改诊断报告原因模版库")
    public AjaxResult edit(@RequestBody SysCompanyReportReason sysCompanyReportReason)
    {
        sysCompanyReportReason.setUpdateBy(getLoginUser().getUsername());
        return toAjax(sysCompanyReportReasonService.updateSysCompanyReportReason(sysCompanyReportReason));
    }

    /**
     * 删除诊断报告原因模版库
     */
  //  @PreAuthorize("@ss.hasPermi('system:reason:remove')")
    @Log(title = "诊断报告原因模版库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reasonIds}")
    @ApiOperation(value = "删除诊断报告原因模版库")
    public AjaxResult remove(@PathVariable Long[] reasonIds)
    {
        return toAjax(sysCompanyReportReasonService.deleteSysCompanyReportReasonByReasonIds(reasonIds));
    }
}
